package com.jcli.fx3u;

import com.jcli.HslCommunication.Profinet.Melsec.MelsecA1ENet;
import com.jcli.HslCommunication.Core.Types.OperateResultExOne;

public class _01_Main {

    public static void main(String[] args) {
        // 创建Melsec A1E客户端对象并与PLC通信
        MelsecA1ENet melsec_net = new MelsecA1ENet("192.168.1.11", 3000);
        melsec_net.SetPersistentConnection();

        // 读取D497的值
        OperateResultExOne<Boolean> readD497 = melsec_net.ReadBool("D497");
        if (readD497.IsSuccess) {
            boolean d497Value = readD497.Content;
            if (d497Value) {
                // 读取D500-D700的值
                OperateResultExOne<byte[]> readD500D700 = melsec_net.Read("D500", (short) 201); // 201个字的长度
                if (readD500D700.IsSuccess) {
                    // 在这里处理D500-D700的值
                    // ...
                    
                    // 将D497的值改写为0
                    melsec_net.Write("D497", false);
                    System.out.println("D497的值已成功改写为0。");
                } else {
                    System.out.println("读取D500-D700失败：" + readD500D700.Message);
                }
            } else {
                System.out.println("D497的值不为1，无需执行操作。");
            }
        } else {
            System.out.println("读取D497失败：" + readD497.Message);
        }

        // 关闭连接
        melsec_net.ConnectClose();
    }
}
